package com.game.server.message.proto.execute;

import com.comm.ISession;

import com.game.majiang.config.LogManager;
import com.game.majiang.logic.LogicClient;
import com.game.majiang.logic.LogicServer;
import com.game.majiang.vo.CheckCodeVo;
import com.game.server.db.dao.CallProcess;
import com.game.server.message.proto.in.AbstractPhoneRegisterReq;
import com.game.server.message.proto.out.PhoneRegisterRsp;
import com.game.server.util.Util;
import lombok.extern.log4j.Log4j;


public class PhoneRegisterReq extends AbstractPhoneRegisterReq {

    @Override
    public void Execute(ISession session) {
        log.info("手机注册");
        PhoneRegisterRsp rsp = new PhoneRegisterRsp();
        rsp.setAcc(this.acc);
        rsp.setPass(this.getPass());
        rsp.setIsok(1);
        if (this.acc!=null && this.acc.length()==11 && Util.checkPhone(this.acc)){
            LogManager.getInstance().Log("this.acc=="+this.acc);
            LogManager.getInstance().Log("tthis.pass=="+this.pass);
            LogManager.getInstance().Log("tthis.yzm=="+this.yzm);
            boolean  checkCode = CheckCodeVo.checkCode(this.acc, Integer.parseInt(this.yzm));
            System.out.println(checkCode);
            if(!checkCode){
                rsp.setIsok(2);
            } else {
                int isok = CallProcess.RegisterUser(this.acc, Util.Md5(this.pass), this.yzm);
                LogManager.getInstance().Log("this.isok=="+ String.valueOf(isok));

                if (isok>100){
                    rsp.setIsok(0);
                }else{
                    rsp.setIsok(isok);
                }
            }
        }

        session.send(rsp.Serialize());
    }

}
